<template>
	<view class="search-controller">
		<web-header :select_name="'home'" :in_search_page='true' :search_value='search_value'></web-header>

		<view class="content_template">
			<!-- 左侧内容 -->

			<view class="content_left">

				<view class="web_show">
					<view class="search_input" style="">
						<input v-model="search_value" class="input" />
						<view class="btn" @click="web_search">
							<image class="img_logo" src="/static/2.2/search_logo.png"></image>
						</view>
					</view>
				</view>
				<view style="padding: 0rpx 10rpx;">
					<u-tabs @click='tabsclick'    lineColor="#008796"
							itemStyle='padding-left: 10rpx; padding-right: 10rpx; height: 64rpx;font-size: 24rpx; flex-shrink:1; flex-grow:1; ' :activeStyle="{
					color: '#008796',
					fontWeight: 'bold', 
					fontSize:'24rpx', }
					 " :inactiveStyle="{
					color: '#606266',
					           
					fontSize:'24rpx',  }" :list="list" :current='type' :is-scroll="false"></u-tabs>
					
						
				</view>


				<view class="h5_content">
					<!-- 有数据 -->
					<view v-if="has_data">
						<!-- 标题模板 -->
						<view class="data_list">

							<view v-if="specialColumnDataList.length > 0">
								<view class="header_title">
									<view class="header">
										<view class="title">热门资讯</view>
										<!-- // 1:同情用药，2:海外新药，3：临床招募，4：商城，5：热门资讯，6：药库 -->
										<view v-if="type == 0" @click="more_click(5)">
											<image src="/static/2.1/btn_more.png"></image>
											<text class="more">更多</text>
										</view>
									</view>
									<view class="line"></view>
								</view>

								<view>
									<!-- 热门资讯模板 -->
									<view v-for="(item,index) in specialColumnDataList">
										<view @click="specialColumnDataHot_click(item)">
											<article-cell :item="item">
											</article-cell>
										</view>

										<!-- <view v-if="index == 2">
											<image class="ad_01" src="/static/2.2/ad_01.png"></image>
										</view> -->
									</view>

								</view>
							</view>

							<!-- 标题模板 -->
							<view v-if="overseasList.length > 0">
								<view class="header_title">
									<view class="header">
										<view class="title">海外新药</view>
										<!-- // 1:同情用药，2:海外新药，3：临床招募，4：商城，5：热门资讯，6：药库 -->
										<view v-if="type == 0" @click="more_click(2)">
											<image src="/static/2.1/btn_more.png"></image>
											<text class="more">更多</text>
										</view>
									</view>
									<view class="line"></view>
								</view>
								<view>
									<!-- 海外新药模板 -->
									<view v-for="item in overseasList" @click="overseasHot_click(item)">
										<new-drugs-cell :item="item"></new-drugs-cell>
									</view>

								</view>
							</view>

							<!-- 标题模板 -->
							<view v-if="storeServiceList.length > 0">
								<view class="header_title">
									<view class="header">
										<view class="title">商城</view>
										<!-- // 1:同情用药，2:海外新药，3：临床招募，4：商城，5：热门资讯，6：药库 -->
										<view v-if="type == 0" @click="more_click(4)">
											<image src="/static/2.1/btn_more.png"></image>
											<text class="more">更多</text>
										</view>
									</view>
									<view class="line"></view>
								</view>

								<!-- 商城模板 -->
								<view class="mall_list">
									<view v-for="item in storeServiceList" @click="storeServiceHot_click(item)">
										<mall-cell :item="item"></mall-cell>
									</view>

								</view>
							</view>


							<!-- 标题模板 -->
							<view v-if="sympathizingList.length > 0">
								<view class="header_title">
									<view class="header">
										<view class="title">同情用药</view>
										<!-- // 1:同情用药，2:海外新药，3：临床招募，4：商城，5：热门资讯，6：药库 -->
										<view v-if="type == 0" @click="more_click(1)">
											<image src="/static/2.1/btn_more.png"></image>
											<text class="more">更多</text>
										</view>
									</view>
									<view class="line"></view>
								</view>

								<view>
									<!-- 同情用药模板 -->
									<view @click='sympathizingHot_click(item)' v-for="item in sympathizingList">
										<information-cell :item="item"></information-cell>
									</view>

								</view>
							</view>

							<!-- 标题模板 -->
							<view v-if="clinicalRecruitmentList.length > 0">
								<view class="header_title">
									<view class="header">
										<view class="title">临床招募</view>
										<!-- // 1:同情用药，2:海外新药，3：临床招募，4：商城，5：热门资讯，6：药库 -->
										<view v-if="type == 0" @click="more_click(3)">
											<image src="/static/2.1/btn_more.png"></image>
											<text class="more">更多</text>
										</view>
									</view>
									<view class="line"></view>
								</view>

								<view>
									<!-- 同情用药模板 -->
									<view @click='clinicalRecruitmentList_cllick(item)'
										v-for="item in clinicalRecruitmentList">
										<clinical-recruitment-cell :item='item'></clinical-recruitment-cell>
									</view>

								</view>
							</view>
							<!--  -->
							<view v-if="medicineStorehouseList.length > 0">
								<view class="header_title">
									<view class="header">
										<view class="title">药库</view>
										<!-- // 1:同情用药，2:海外新药，3：临床招募，4：商城，5：热门资讯，6：药库 -->
										<view v-if="type == 0" @click="more_click(6)">
											<image src="/static/2.1/btn_more.png"></image>
											<text class="more">更多</text>
										</view>
									</view>
									<view class="line"></view>
								</view>

								<view>
									<!-- 药库模板 -->
									<view class="web_show ">
										<view class="pharmacy_content">
											<view @click='medicineStorehouseList_cllick(item)'
												v-for="item in medicineStorehouseList">
												<pharmacy-cell :item='item'></pharmacy-cell>
											</view>
										</view>
									</view>
									<view class="h5_show">
										<view @click='medicineStorehouseList_cllick(item)'
											v-for="item in medicineStorehouseList">
											<pharmacy-cell :item='item'></pharmacy-cell>
										</view>
									</view>


								</view>
							</view>
						</view>
						<view class="page-pagination" v-if="type != 0 && has_data == true">
							<page-pagination style="margin-bottom: 60rpx;" @change="page_change"
								:currentPage='page.current' :total="page.total" color="#048597" :showAround="true"
								:btnText="true" :forceEllipses="true">
							</page-pagination>
						</view>


					</view>
					<view v-if="has_data == false">
						<view class="searc_no_data">
							<image class="img" src="/static/2.2/no_data.png"></image>
							<view class="text1">未找到搜索页面</view>
							<view class="text2">对搜索结果不满意？试试联系客服</view>
							<view class="phone_bottum">
								<image class="phone_img" src="/static/2.2/phone_search.png"></image>
								<view class="text"> 4008622030</view>
							</view>
						</view>
					</view>
					<!-- <image class="ad_02" src="/static/2.2/ad_02.png"></image> -->

				</view>
			</view>

			<!-- 右边模板 -->
			<view class="content_right">
				<filtrate-card></filtrate-card>

				<!-- 标题模板 -->
				<!-- <view class="header_title">
					<view class="header">
						<view class="title">临床招募</view>
						<navigator url="/pages/clinical_recruitment/clinical_recruitment">
							<image src="/static/2.1/btn_more.png"></image>
							<text class="more">更多</text>
						</navigator>
					</view>
					<view class="line"></view>
				</view>

				<view class="recruiting_list">
					<view class="recruiting_cell" @click="open_clinical_recruitment_info(item)"
						v-for="item in clinicalRecruitmentList">
						<view class="left">
							<view class="point"></view>
							<view class="line"></view>
						</view>
						<view class="name">{{item.title}}</view>

					</view>


				</view>
 -->

			</view>

		</view>



		<web-foot></web-foot>
	</view>
</template>

<script>
	import web_header from '@/components/web-header.vue'
	import web_foot from '@/components/web-foot.vue'
	import filtrate_card from '@/components/filtrate_card.vue'
	// import information_cell from '@/components/information_cell/information_cell.vue'

	export default {

		components: {
			'web-header': web_header,
			'web-foot': web_foot,
			'filtrate-card': filtrate_card,
			// 'information-cell':information_cell
		},
		data() {
			return {
				has_data: false, //是否有搜索结果
				type: 0,
				search_value: '',
				page: {
					total: 88,
					size: 10,
					current: 1
				},
				specialColumnDataList: [],
				overseasList: [],
				storeServiceList: [],
				sympathizingList: [],
				clinicalRecruitmentList: [],
				medicineStorehouseList: [],
				list: [{
					name: '综合'
				}, {
					name: '同情用药'
				}, {
					name: '海外新药',

				}, {
					name: '临床招募',

				}, {
					name: '商城',

				}, {
					name: '热门资讯',

				}, {
					name: '药库',

				}],
			}
		},
		onLoad(e) {
			var s_text = e.s_text;
			if (s_text) {
				this.search_value = s_text;
				console.log(e)
			}
		},
		onShow() {
			uni.$on('search', function(e) {
				console.log("search on")
				console.log(e)
			})
			this.get_data()
		},
		methods: {
			navigator_url(url) {
				uni.navigateTo({
					url: url
				})
			},
			tabsclick(e) {
				console.log(e)
				this.type = e.index
				this.get_data()
			},
			// 1:同情用药，2:海外新药，3：临床招募，4：商城，5：热门资讯，6：药库
			more_click(index) {
				this.page.current = 1
				this.type = index
				this.get_data()
			},
			page_change(currentPage, type) {
				console.log("点击了" + type + "，当前页：" + currentPage);
				this.page.current = currentPage
				this.get_data()
				// this.page.currentPage = currentPage;

			},
			web_search() {
				this.type = 0
				this.page.current = 0
				this.get_data()
			},
			get_data() {

				var that = this;

				var para = {
					keywords: this.search_value
				}
				// 1:同情用药，2:海外新药，3：临床招募，4：商城，5：热门资讯，6：药库
				if (this.type != 0) {
					para['type'] = this.type
					para['page'] = this.page.current
					para['pageSize'] = 10

				}
				// page: this.page.current,
				// type: 1, //	1:海外新药，4:同情用药
				// if(this.search_value == null || this.search_value == ''){
				// 	para = {}
				// }
				//banner
				this.service("/website/search", 'get', para).then(res => {
					console.log(res)
					var response_data = res.data;

					if (res.code == 200) {
						that.has_data = true;
						if (that.type == 0) {
							// sympathizingList 同情用药
							// overseasList 海外新药
							// clinicalRecruitmentList 临床招募
							// storeServiceList 商城
							// medicineStorehouseList 药库
							// specialColumnDataList 热门资讯（暂未返回）
							that.clinicalRecruitmentList = response_data.clinicalRecruitmentList
							that.medicineStorehouseList = response_data.medicineStorehouseList
							that.overseasList = response_data.overseasList
							that.storeServiceList = response_data.storeServiceList
							that.sympathizingList = response_data.sympathizingList
							that.specialColumnDataList = response_data.specialColumnDataList
							if (that.clinicalRecruitmentList.length == 0 &&
								that.medicineStorehouseList.length == 0 &&
								that.overseasList.length == 0 &&
								that.storeServiceList.length == 0 &&
								that.sympathizingList.length == 0 &&
								that.specialColumnDataList.length == 0) {
								this.has_data = false
							}


						} else {
							that.clinicalRecruitmentList = []
							that.medicineStorehouseList = []
							that.overseasList = []
							that.storeServiceList = []
							that.sympathizingList = []
							that.specialColumnDataList = []
							// that.$forceUpdate()
							that.page = response_data;
							// 1:同情用药，2:海外新药，3：临床招募，4：商城，5：热门资讯，6：药库
							var records = response_data.records
							if (records.length == 0) {
								this.has_data = false
							}

							if (that.type == 1) {
								that.sympathizingList = records

							}
							if (that.type == 2) {
								that.overseasList = records
							}
							if (that.type == 3) {
								that.clinicalRecruitmentList = records
							}
							if (that.type == 4) {
								that.storeServiceList = records
								// that.$set(that,'storeServiceList',records)
							}
							if (that.type == 5) {
								that.specialColumnDataList = records
								// that.$set(that,'specialColumnDataList',records)
							}
							if (that.type == 6) {
								that.medicineStorehouseList = records
								// that.$set(that,'medicineStorehouseList',records)
							}
							// setTimeout(()=>{
							// 	that.$forceUpdate()
							// },100)

						}


					} else {
						that.has_data = false;
					}

					// that.banners = res.data;
				})

			},
			banner_click(index) {
				console.log(index)
				let item = this.banners[index]
				console.log(item)
				window.open(item.clickLink)
			},
			specialColumnDataHot_click(item) {
				console.log(item)
				uni.navigateTo({
					url: '/pages/article/article_info?id=' + item.id
				})
			},
			// 详情
			clinicalRecruitmentList_cllick(item) {
				uni.navigateTo({
					url: '/pages/clinical_recruitment/clinical_recruitment_info?id=' + item.id
				})
			},
			medicineStorehouseList_cllick(item) {
				uni.navigateTo({
					url: '/pages/pharmacy/pharmacy_info?id=' + item.id
				})
			},
			overseasHot_click(item) {
				console.log(item)
				uni.navigateTo({
					url: '/pages/new_drugs/new_drugs_info/new_drugs_info?id=' + item.id
				})
			},
			storeServiceHot_click(item) {
				uni.navigateTo({
					url: '/pages/mall/mall'
				})
			},
			sympathizingHot_click(item) {
				console.log(item)
				uni.navigateTo({
					url: '/pages/information/information_info?id=' + item.id
				})
			},
			//详情
			open_clinical_recruitment_info(item) {
				uni.navigateTo({
					url: '/pages/clinical_recruitment/clinical_recruitment_info?id=' + item.id
				})
			},



		}
	}
</script>

<style lang="scss">
	@import '@/pages/search/search.scss';
</style>
